import sys

def chinese_to_unicode(text):
    return ''.join([f'\\\\u{ord(char):04x}' for char in text])

def convert_file(input_file, output_file):
    try:
        # 读取输入文件
        with open(input_file, 'r', encoding='utf-8') as f_in:
            content = f_in.read()
        
        # 转换内容
        converted_content = chinese_to_unicode(content)
        
        # 写入输出文件
        with open(output_file, 'w', encoding='utf-8') as f_out:
            f_out.write(converted_content)
        
        print(f"转换成功。输出已写入 {output_file}")
    except FileNotFoundError:
        print(f"错误：找不到文件 {input_file}")
    except IOError as e:
        print(f"错误：读写文件时出现问题 - {e}")
    except Exception as e:
        print(f"发生未知错误 - {e}")

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("用法: python script.py 输入文件 输出文件")
        sys.exit(1)
    
    input_file = sys.argv[1]
    output_file = sys.argv[2]
    convert_file(input_file, output_file)